# 构建复杂模型

import tensorflow as tf
from tensorflow import keras
import numpy as np
from tensorflow.keras import layers

# 函数式api

input_x = tf.keras.Input(72, )

hidden1 = layers.Dense(32, activation=tf.keras.activations.relu)(input_x)
hidden2 = layers.Dense(32, activation=tf.keras.activations.relu)(hidden1)
output = layers.Dense(10, activation=tf.keras.activations.softmax)(hidden2)

# 构建模型实力

model = tf.keras.Model(inputs=input_x, outputs=output)

model.compile(optimizer=tf.keras.optimizers.Adam(0.001),
              loss=tf.keras.losses.categorical_crossentropy,
              metrics=['accuracy'])

train_x = np.random.random((1000, 72))
train_y = np.random.random((1000, 10))

val_x = np.random.random((200, 72))
val_y = np.random.random((200, 10))

model.fit(train_x, train_y, batch_size=32, epochs=5)
